package com.boot.controller;

import com.boot.bean.UserDo;
import com.boot.enums.ResultEnum;
import com.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.RequestContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public Object login(String username, String password,HttpServletRequest request) {
        UserDo login = userService.login(username, password);
        if (login == null) {
            throw new RuntimeException("not found user");
        }
        request.getSession().setAttribute(ResultEnum.USERKEY.getMessage(),login);
        return HttpStatus.OK.value();
    }
}
